#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "frmaddemployee.h"
#include "frmemplist.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->tbNumber->setText(QString::number(EmployeeContainer::employeelist->size()));
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_actionAdd_triggered()
{
    FrmAddEmployee *f = new FrmAddEmployee;
    f->show();
}



void MainWindow::on_actionList_triggered()
{
    FrmEmpList *f = new FrmEmpList;
    f->show();
}

void MainWindow::on_actionQuit_triggered()
{
    this->close();
}

void MainWindow::on_actionLoad_triggered()
{
    FrmEmpList fr;
    fr.readData();
    ui->tbNumber->clear();
    ui->tbNumber->setText(QString::number(EmployeeContainer::employeelist->size()));
}

void MainWindow::on_actionSave_triggered()
{
    FrmEmpList fs;
    fs.saveData();
}

void MainWindow::on_actDeleteDate_triggered()
{
    if(QMessageBox::Yes == QMessageBox::question(this, "删除提示", "确定删除嘛？", QMessageBox::Yes | QMessageBox::No)){
        ofstream ofs("Employee_list.txt", ios::out);
        if(ofs){
            remove("Employee_list.txt");
            QMessageBox::information(this, "提示", "删除成功!");
        }else{
            QMessageBox::critical(this, "提示", "本地无数据!");
        }
        ofs.close();
    }
}

void MainWindow::on_pushButton_clicked()
{
    ui->tbNumber->clear();
    ui->tbNumber->setText(QString::number(EmployeeContainer::employeelist->size()));
}
